# coding : UTF-8
"""
author：BingBO   time：2023.03.16
Theme：
notes：
"""

import Hikvision_CameraCall
import laser_contr
import time


# from MvImport import MvCameraControl_header

def capSingle():
    type = "V"
    thickness_angle = "6_up_2mm_15_"
    type_thickness = type + thickness_angle
    # 调用相机 + 控制激光开关
    laser_contr.Four_CC(0, 0, 0, 0)
    for i in range(20):  # 采集图像数量
        # 图像开始序号
        i = i + 0
        typeIdx = type_thickness + str(i)

        # 打开辅助灯光：提示 1.拍摄区域 2.移动工件
        laser_contr.Four_CC(1, 1, 1, 0)
        time.sleep(4)

        # 关闭辅助灯光：等待1S后拍摄
        laser_contr.Four_CC(1, 1, 0, 0)
        time.sleep(1)
        Hikvision_CameraCall.imgCapture(typeIdx)
        print("------ 图像%d采集完毕 -------" % i)

    # 采集完毕
    laser_contr.Four_CC(1, 1, 1, 1)
    laser_contr.Four_CC(0, 0, 0, 0)
    print("\n********** ALL DONE！**********")
    # 再显示区域
    laser_contr.Four_CC(1, 1, 1, 0)


def capMultiple():
    type = "S"
    thickness_angle = "6_g"
    type_thickness = type + thickness_angle
    # 调用相机 + 控制激光开关
    laser_contr.Four_CC(0, 0, 0, 0)
    for i in range(0, 72):
        # 图像开始序号
        i = i + 26
        typeIdx = type_thickness + str(i + 1)
        print("********** Group %d START！**********" % (i + 1))
        laser_contr.Four_CC(0, 0, 0, 0)
        Hikvision_CameraCall.imgCapture(typeIdx + "_1")
        # 三线
        laser_contr.Four_CC(1, 1, 0, 0)
        Hikvision_CameraCall.imgCapture(typeIdx + "_2")
        # 交叉
        laser_contr.Four_CC(0, 0, 1, 1)
        Hikvision_CameraCall.imgCapture(typeIdx + "_3")
        # 混合
        laser_contr.Four_CC(1, 1, 1, 1)
        Hikvision_CameraCall.imgCapture(typeIdx + "_4")
        # print(" END！")
        input("Enter To Continue ......")
    print("********** ALL DONE！**********")
    laser_contr.Four_CC(0, 0, 0, 0)
    laser_contr.Four_CC(1, 1, 1, 1)


def timeRecord():
    """
    时间区间：打开第1个继电器，采集图像保存，关闭第1个继电器，打开第二个继电器，保存第二张图片
    """
    timeList = list()
    for i in range(0, 50):
        # 图像开始序号
        i = i + 0
        laser_contr.two_CC(0, 0)
        print("********** Group %d START！**********" % (i + 1))
        t1 = time.monotonic()  # 开始记录时间
        # 交叉
        laser_contr.two_CC(0, 1)
        Hikvision_CameraCall.imgCapture(str(i + 1) + "Cross")
        # 平行
        laser_contr.two_CC(1, 0)
        Hikvision_CameraCall.imgCapture(str(i + 1) + "Parall")
        t2 = time.monotonic()  # 结束记录时间
        print("ProcessTime : %s ms" % ((t2 - t1) * 1000))
        timeList.append((t2 - t1) * 1000)
        time.sleep(0.5)
    print("********** ALL DONE！**********")
    print("记录列表", timeList)
    print("共储存数据：%d 个" % len(timeList))
    print("平均处理时间：%s ms" % (sum(timeList) / len(timeList)))


# capMultiple()
timeRecord()
